<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>解构赋值和展开运算符</title>
</head>
<body>
<script>
    //解构赋值 =
    //主要针对于引用数据类型(Object, Array),使我们可以更快速和方便的获取我们想要获取的值
    //解构赋值等号两边 数据类型必须一致

    let a , b , c;
    [a, b] = [1, 2];
    console.log(a);//1
    console.log(b);//2
    ({a, b} = {a: 10, b: 20});
    console.log(a);//10
    console.log(b);//20

    //... 展开运算符  剩余操作符
    let arr = [1, 2, 3, 4];
    console.log("解构", ...arr);//展开--->  1 2 3 4
    let arr2 = [...arr];//[1, 2, 3, 4]
    console.log("Array2", arr2);//1 2 3 4
//    arr == arr2

/*
    function fn1(a) {
        a = a || 1;
        console.log("fn1=>", a);
    }
    function fn1(a = 1) {
        console.log("fn1--->",a)
    }
    fn1();
    fn1(3);*/

/*    var o = {p: 42, q: true};
    var {p: foo, q: bar} = o;

    console.log(foo); // 42
    console.log(bar); // true */


//    别名(小名)
/*    let obj = {
            name: 'Mike Smith',
            family: {
                mother: 'Jane Smith',
                father: 'Harry Smith',
                sister: 'Samantha Smith'
            },
            age: 35
        };
    ({name: n, family: {father: f}} = obj);

    console.log(n, f); // ES6;*/


    let mike = { //麦克
            name: 'Mike Smith', //麦克 斯密斯
            age: 35,
            father: {
                name: 'Harry Smith',
                age: 55
            }
        };

//    let name1 = mike.name;
//    let name2 = mike.father.name;

    let {name: name1, father: {name: name2}} = mike;

    console.log(name1, name2); //

</script>
</body>
</html>